/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.agh.io.gpstracker.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * 
 * @author wkedzior
 */
@Entity
@Table(name = "messages")
@NamedQueries( {
		@NamedQuery(name = "Messages.findAll", query = "SELECT m FROM Messages m"),
		@NamedQuery(name = "Messages.findById", query = "SELECT m FROM Messages m WHERE m.id = :id"),
		@NamedQuery(name = "Messages.findByTitle", query = "SELECT m FROM Messages m WHERE m.title = :title"),
		@NamedQuery(name = "Messages.findByType", query = "SELECT m FROM Messages m WHERE m.type = :type") })
public class Messages implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
	@Column(name = "title")
	private String title;
	@Lob
	@Column(name = "message")
	private String message;
	@Column(name = "type")
	private Short type;
	@JoinColumn(name = "user_id1", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private User user;
	@Column(name = "user_id1", insertable = false, updatable = false)
	private Integer userId;
	@JoinColumn(name = "master_id", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private User user1;

	public Messages() {
	}

	public Messages(Integer id) {
		this.id = id;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Messages)) {
			return false;
		}
		Messages other = (Messages) object;
		if ((this.id == null && other.id != null)
				|| (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	public Integer getId() {
		return id;
	}

	public String getMessage() {
		return message;
	}

	public String getTitle() {
		return title;
	}

	public Short getType() {
		return type;
	}

	public User getUser() {
		return user;
	}

	public User getUser1() {
		return user1;
	}

	public Integer getUserId() {
		return userId;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setType(Short type) {
		this.type = type;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setUser1(User user1) {
		this.user1 = user1;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	@Override
	public String toString() {
		return "pl.edu.agh.io.gpstracker.model.Messages[id=" + id + "]";
	}

}
